package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.ServiceDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class TmsController {
    @Autowired
    ServiceDao serviceDao;

    @RequestMapping("/zhe")
    public Object zhe(){
        List<Map> maps = serviceDao.zhe();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject datajsonObject = new JSONObject();
// x{}
        JSONArray xarray = new JSONArray();
        for (Map map : maps) {
            xarray.add(map.get("各小时"));
        }
        datajsonObject.put("categories",xarray);

//y{}
        JSONArray yarray = new JSONArray();
        JSONObject object = new JSONObject();
        object.put("name","各小时");
        yarray.add(object);

        JSONArray yarray2 = new JSONArray();
        for (Map map : maps) {
            yarray2.add(map.get("独立访客数"));
        }
        object.put("data",yarray2);


        datajsonObject.put("series",yarray);
        jsonObject.put("data",datajsonObject);
        return jsonObject;
    }

    @RequestMapping("/lun")
    public Object lun(){
        List<Map> maps = serviceDao.lun();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataobject = new JSONObject();

        JSONArray columns = new JSONArray();
        dataobject.put("columns",columns);

        JSONObject CC1 = new JSONObject();
        CC1.put("name","来源");
        CC1.put("id","subsys");
        columns.add(CC1);

        JSONObject CC2 = new JSONObject();
        CC2.put("name","订单总额");
        CC2.put("id","module");
        columns.add(CC2);

        JSONObject CC3 = new JSONObject();
        CC3.put("name","下单人数");
        CC3.put("id","business");
        columns.add(CC3);

        JSONObject CC4 = new JSONObject();
        CC4.put("name","订单数");
        CC4.put("id","name");
        columns.add(CC4);

        JSONArray rows = new JSONArray();
        for (Map map : maps) {
            JSONObject mapsobject = new JSONObject();
            mapsobject.put("subsys",map.get("来源"));
            mapsobject.put("module",map.get("订单总额"));
            mapsobject.put("business",map.get("下单人数"));
            mapsobject.put("name",map.get("订单数"));
            rows.add(mapsobject);
        }
        dataobject.put("rows",rows);
        jsonObject.put("data",dataobject);
        return jsonObject;
    }

    @RequestMapping("/shu")
    public Object shu(){
        List<Map> maps = serviceDao.shu();
        JSONObject dataobject = new JSONObject();
        dataobject.put("status",0);
        dataobject.put("msg","");

        JSONArray array = new JSONArray();
        for (Map map : maps) {
            JSONObject mapss = new JSONObject();
            mapss.put("value",map.get("ss"));
            array.add(mapss);
        }

        dataobject.put("data",array);
        return dataobject;
    }

    @RequestMapping("/bo")
    public Object bo(){
        List<Map> maps = serviceDao.bo();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataobject = new JSONObject();

        JSONArray columns = new JSONArray();
        jsonObject.put("columns",columns);

        JSONObject CC1 = new JSONObject();
        CC1.put("name","dd");
        CC1.put("id","subsys");
        columns.add(CC1);

        JSONObject CC2 = new JSONObject();
        CC2.put("name","下单金额");
        CC2.put("id","module");
        columns.add(CC2);

        JSONArray rows = new JSONArray();
        for (Map map : maps) {
            JSONObject mapss = new JSONObject();
            mapss.put("subsys",map.get("dd"));
            mapss.put("module",map.get("下单金额"));
            rows.add(mapss);
        }

        jsonObject.put("rows",rows);
        jsonObject.put("data",dataobject);
        return jsonObject;
    }
}
